package com.whlilong.jxc.view;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

import com.whlilong.jxc.constants.IAppConstants;
import com.whlilong.jxc.sys.CacheImage;
import com.whlilong.jxc.sys.IImageKey;
import com.whlilong.jxc.util.ViewerChange;

/**金卡中心视图
 * @author sjy
 *
 */
public class GoldCenterView extends ViewPart implements ISelectionListener{

	private Button hyinfo;	//会员信息
	private Button hyprice;	//会员价格	
	private Button hyjf;	//会员积分
	private Button hyzc;	//会员注册
	private Button hycz;	//会员价格

	public GoldCenterView() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void createPartControl(Composite parent) {
		// TODO Auto-generated method stub
		createContent(parent);
		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().addSelectionListener(this);
	}

	private void createContent(Composite parent) {
		// TODO Auto-generated method stub
		Composite composite = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.numColumns = 3;
		layout.marginTop = 10;
		layout.marginBottom = 10;
		layout.marginRight = 10;
		layout.marginLeft = 10;
		layout.makeColumnsEqualWidth = true;

		composite.setLayout(layout);
		composite.setBackgroundImage(CacheImage.getINSTANCE().getImage(
				IAppConstants.APPLICATION_ID, IImageKey.FUNCTIONS_BG));
	
		createButton(composite);
	}
	
	private void createButton(Composite composite) {
		// TODO Auto-generated method stub
		GridData gd = new GridData(GridData.CENTER);
		gd.horizontalIndent = 30;
		gd.verticalIndent = 20;
		gd.widthHint = 130;
		gd.heightHint = 50;
		

		hyinfo = new Button(composite, SWT.NONE);
		hyinfo.setImage(CacheImage.getINSTANCE().getImage(
				IAppConstants.APPLICATION_ID, IImageKey.ceshi));
		hyinfo.setText("会员信息");
		hyinfo.setToolTipText(hyinfo.getText());
		hyinfo.setLayoutData(gd);
		
		hyprice = new Button(composite, SWT.NONE);
		hyprice.setImage(CacheImage.getINSTANCE().getImage(
				IAppConstants.APPLICATION_ID, IImageKey.ceshi));
		hyprice.setText("会员价格");
		hyprice.setToolTipText(hyprice.getText());
		hyprice.setLayoutData(gd);
		
		hyjf = new Button(composite, SWT.NONE);
		hyjf.setImage(CacheImage.getINSTANCE().getImage(
				IAppConstants.APPLICATION_ID, IImageKey.ceshi));
		hyjf.setText("会员积分");
		hyjf.setToolTipText(hyjf.getText());
		hyjf.setLayoutData(gd);
		
		hyzc = new Button(composite, SWT.NONE);
		hyzc.setImage(CacheImage.getINSTANCE().getImage(
				IAppConstants.APPLICATION_ID, IImageKey.ceshi));
		hyzc.setText("会员注册");
		hyzc.setToolTipText(hyzc.getText());
		hyzc.setLayoutData(gd);
		
		hycz = new Button(composite, SWT.NONE);
		hycz.setImage(CacheImage.getINSTANCE().getImage(
				IAppConstants.APPLICATION_ID, IImageKey.ceshi));
		hycz.setText("会员充值");
		hycz.setToolTipText(hycz.getText());
		hycz.setLayoutData(gd);
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

	@Override
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
		if (!selection.isEmpty()) {
			IViewPart vp = getViewSite().getPage().findView(
					IAppConstants.systemManagerview_id);

			Table table = ((SystemManagerView) vp).getTableViewer().getTable();
			ViewerChange.getInstance().refreshView(table);
		}		
	}

}
